package cn.tedu.csmall520.stock.webapi.service.impl;

import cn.tedu.csmall520.commons.exception.CoolSharkServiceException;
import cn.tedu.csmall520.commons.pojo.stock.dto.StockReduceCountDTO;
import cn.tedu.csmall520.commons.restful.ResponseCode;
import cn.tedu.csmall520.stock.service.IStockService;
import cn.tedu.csmall520.stock.webapi.mapper.StockMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//DubboService注解，标记的业务实现类，其中所有的方法都会注册到nacos中
//其他服务启动”订阅“，就会”发现“当前类中所有的服务，随时都可以调用
@DubboService
@Service
@Slf4j
public class StockServiceImpl implements IStockService {

    @Autowired
    private StockMapper stockMapper;

    @Override
    public void reduceCount(StockReduceCountDTO stockReduceCountDTO) {
        log.debug("开始处理修改商品库存的业务");
        int update = stockMapper.update(stockReduceCountDTO.getCommodityCode(),
                stockReduceCountDTO.getReduceCount());
        if (update == 0) {
            throw new CoolSharkServiceException(ResponseCode.BAD_REQUEST,"库存不足");
        }
        log.debug("修改库存成功");



    }
}
